Importing required packages¶
In [1]:
import pygame as pg
import OpenGL.GL as opg
pygame 2.1.2 (SDL 2.0.16, Python 3.8.10) Hello from the pygame community. https://www.pygame.org/contribute.html
Definition of App class¶
In [2]:
class App:
def __init__(self, title):
# initialize pygame engine
pg.init()
pg.display.set_mode((500,600), pg.OPENGL|pg.DOUBLEBUF)
pg.display.set_caption(title)
self.clock = pg.time.Clock()
# initialize opengl
opg.glClearColor(0.17,0.24,0.39,1) # RGBA Color Mode
self.minLoop()
def minLoop(self):
opg.running = True
# event loop
while(opg.running):
# checking events
for evt in pg.event.get():
if(evt.type == pg.QUIT):
opg.running = False
# refreshing screen
opg.glClear(opg.GL_COLOR_BUFFER_BIT)
pg.display.flip()
# timing
self.clock.tick(60)
self.quit()
# for deallocation of memory and resources
def quit(self):
pg.quit()
print("App Closed")
Driver Code¶
In [3]:
if __name__=="__main__":
myApp = App('App window')
App Closed